package org.zheng.shop.entity;

import java.time.LocalDateTime;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

/**
 * 咨询消息实体类
 * 用于存储咨询会话中的消息记录
 */
@Entity
@Table(name = "consultation_messages")
public class ConsultationMessage {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    /**
     * 所属会话ID
     */
    @Column(name = "session_id", nullable = false)
    private Long sessionId;
    
    /**
     * 发送者ID
     */
    @Column(name = "sender_id", nullable = false)
    private Integer senderId;
    
    /**
     * 发送者姓名
     */
    @Column(name = "sender_name", length = 100, nullable = false)
    private String senderName;
    
    /**
     * 消息内容
     */
    @Column(name = "content", columnDefinition = "TEXT", nullable = false)
    private String content;
    
    /**
     * 消息类型：TEXT(文本), IMAGE(图片), FILE(文件), SYSTEM(系统消息)
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "message_type", nullable = false)
    private MessageType messageType = MessageType.TEXT;
    
    /**
     * 发送者类型：USER(用户), ADMIN(管理员), SYSTEM(系统)
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "sender_type", nullable = false)
    private SenderType senderType;
    
    /**
     * 消息发送时间
     */
    @Column(name = "sent_at", nullable = false)
    private LocalDateTime sentAt;
    
    /**
     * 是否已读（针对接收方）
     */
    @Column(name = "is_read", nullable = false)
    private Boolean isRead = false;
    
    /**
     * 消息状态：SENT(已发送), DELIVERED(已送达), READ(已读)
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false)
    private MessageStatus status = MessageStatus.SENT;
    
    /**
     * 附件URL（如果是图片或文件消息）
     */
    @Column(name = "attachment_url", length = 500)
    private String attachmentUrl;
    
    // 消息类型枚举
    public enum MessageType {
        TEXT,       // 文本消息
        IMAGE,      // 图片消息
        FILE,       // 文件消息
        SYSTEM      // 系统消息
    }
    
    // 发送者类型枚举
    public enum SenderType {
        USER,       // 普通用户
        ADMIN,      // 管理员
        SYSTEM      // 系统
    }
    
    // 消息状态枚举
    public enum MessageStatus {
        SENT,       // 已发送
        DELIVERED,  // 已送达
        READ        // 已读
    }
    
    // 构造函数
    public ConsultationMessage() {
        this.sentAt = LocalDateTime.now();
    }
    
    public ConsultationMessage(Long sessionId, Integer senderId, String senderName,
                             String content, SenderType senderType) {
        this();
        this.sessionId = sessionId;
        this.senderId = senderId;
        this.senderName = senderName;
        this.content = content;
        this.senderType = senderType;
    }
    
    // Getters and Setters
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public Long getSessionId() {
        return sessionId;
    }
    
    public void setSessionId(Long sessionId) {
        this.sessionId = sessionId;
    }
    
    public Integer getSenderId() {
        return senderId;
    }

    public void setSenderId(Integer senderId) {
        this.senderId = senderId;
    }
    
    public String getSenderName() {
        return senderName;
    }
    
    public void setSenderName(String senderName) {
        this.senderName = senderName;
    }
    
    public String getContent() {
        return content;
    }
    
    public void setContent(String content) {
        this.content = content;
    }
    
    public MessageType getMessageType() {
        return messageType;
    }
    
    public void setMessageType(MessageType messageType) {
        this.messageType = messageType;
    }
    
    public SenderType getSenderType() {
        return senderType;
    }
    
    public void setSenderType(SenderType senderType) {
        this.senderType = senderType;
    }
    
    public LocalDateTime getSentAt() {
        return sentAt;
    }
    
    public void setSentAt(LocalDateTime sentAt) {
        this.sentAt = sentAt;
    }
    
    public Boolean getIsRead() {
        return isRead;
    }
    
    public void setIsRead(Boolean isRead) {
        this.isRead = isRead;
    }
    
    public MessageStatus getStatus() {
        return status;
    }
    
    public void setStatus(MessageStatus status) {
        this.status = status;
    }
    
    public String getAttachmentUrl() {
        return attachmentUrl;
    }
    
    public void setAttachmentUrl(String attachmentUrl) {
        this.attachmentUrl = attachmentUrl;
    }
}
